#include <iostream>
#include <cerrno>
#include <cassert>
#include <cstring>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

using namespace std;

#define PATHNAME "." // 项目名
#define PROJID 0x29C // 项目编号

key_t getKey()
{
    key_t key = ftok(PATHNAME, PROJID);
    if (key == -1)
    {
        // 失败，终止进程
        cerr << "ftok fail!  "
             << "errno: " << errno << " | " << strerror(errno) << endl;
    }

    return key;
}

static const int gsize = 4096;
static const mode_t mode = 0666;

int main()
{
    int key = getKey();
    int shmid = shmget(key, gsize, IPC_CREAT);

    shmctl(shmid, IPC_RMID, NULL);

    return 0;
}